﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using qiupeng.Public;
using System.IO;
using SafetyRecordData.Data.DAL;

public partial class SystemManage_ResponBm : Base
{
    Db List = new Db();
    public static string CountsLabel, AllPageLabel, CurrentlyPageLabel, SqlStrStart, SqlStrMid, SqlStr, SqlStrStartCount, SqlStrCount;
    public string CreateMidSql()
    {
        string str = string.Empty;
        if (base.Request.QueryString["key"] != null)
        {
            if (base.Request.QueryString["Name"] != null)
            {
                str = str + " and XingMing like '%" + this.List.GetFormatStr(base.Server.UrlDecode(base.Request.QueryString["Name"])) + "%' ";
            }
            if (base.Request.QueryString["UserName"] != null)
            {
                str = str + " and UserName like '%" + this.List.GetFormatStr(base.Server.UrlDecode(base.Request.QueryString["UserName"])) + "%' ";
            }
            if (base.Request.QueryString["bmname"] != null)
            {
                str = str + " and bumen like '%" + this.List.GetFormatStr(base.Server.UrlDecode(base.Request.QueryString["bmname"])) + "%' ";
            }
            if (base.Request.QueryString["dwname"] != null)
            {
                str = str + " and danweiname like '%" + this.List.GetFormatStr(base.Server.UrlDecode(base.Request.QueryString["dwname"])) + "%' ";
            }
            if (base.Request.QueryString["js"] != null)
            {
                str = str + " and respon like '%" + this.List.GetFormatStr(base.Server.UrlDecode(base.Request.QueryString["js"])) + "%' ";
            }
        }
        return str;


    }
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            BindAttribute();
            DataBindToGridview();
            Bindquanxian();

        }
    }
    public void Bindquanxian()
    {

        List.QuanXianVis(ImageButton4, "iiii7", Session["perstr"].ToString());
        List.QuanXianVis(IMG1, "iiii7", Session["perstr"].ToString());

    }
    public void BindAttribute()
    {

        ImageButton4.Attributes["onclick"] = "javascript:return updatecheck();";


        btnFirst.Attributes["onclick"] = "javascript:return showwait();";
        btnPrev.Attributes["onclick"] = "javascript:return showwait();";
        btnNext.Attributes["onclick"] = "javascript:return showwait();";
        btnLast.Attributes["onclick"] = "javascript:return showwait();";
        Button1.Attributes["onclick"] = "javascript:return chkyema();";
    }
    public void DataBindToGridview()
    {
        SqlStrStart = "select * from (select *,(select a.JgName as jgname from qp_hr_jigou a,qp_hr_JiGou b where a.id=b.ParentNodesID and b.id=c.BuMenId) as danweiname from qp_hr_username c) m where 1=1";
        SqlStrStartCount = "select count(id) from (select *,(select a.JgName as jgname from qp_hr_jigou a,qp_hr_JiGou b where a.id=b.ParentNodesID and b.id=c.BuMenId) as danweiname from qp_hr_username c) m where 1=1";

        SqlStrMid = string.Empty;
        SqlStrMid = CreateMidSql();
        SqlStrMid += " and BuMenId in (" + this.Session["bmqxa"].ToString().Trim() + ") ";
        SqlStr = SqlStrStart + SqlStrMid;//查询
        SqlStrCount = SqlStrStartCount + SqlStrMid;//查询个数

        string Sqlsort = "";
        if (ViewState["OrderBY"] == null)
        {
            ViewState["OrderBY"] = " ORDER BY id desc ";
        }
        Sqlsort = ViewState["OrderBY"].ToString();

        string SQL_GetList_xs = "" + SqlStr + " " + Sqlsort + "";
        GridView1.DataSource = List.GetGrid_Pages_not(SQL_GetList_xs);
        GridView1.DataBind();

        string SQL_GetCount = SqlStrCount;
        CountsLabel = "" + List.GetCount(SQL_GetCount) + "";



        AllPageLabel = Convert.ToString(GridView1.PageCount);
        CurrentlyPageLabel = Convert.ToString(((int)GridView1.PageIndex + 1));


        btnFirst.CommandName = "1";
        btnPrev.CommandName = (GridView1.PageIndex == 0 ? "1" : GridView1.PageIndex.ToString());

        btnNext.CommandName = (GridView1.PageCount == 1 ? GridView1.PageCount.ToString() : (GridView1.PageIndex + 2).ToString());
        btnLast.CommandName = GridView1.PageCount.ToString();
    }




    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataControlRowType itemType = e.Row.RowType;
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);";
            e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);";

        }
    }
    private string CheckCbxDel()
    {
        string str = "0";
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];
            CheckBox Chk = (CheckBox)row.FindControl("CheckSelect");
            Label LabVis = (Label)row.FindControl("LabVisible");
            if (Chk.Checked == true)
            {
                if (str == "")
                {
                    str = LabVis.Text.ToString();
                }
                else
                {
                    str = str + "," + LabVis.Text.ToString();
                }
            }
        }
        return str;
    }


    private string CheckCbxNameDel()
    {
        string str = string.Empty;
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];
            CheckBox Chk = (CheckBox)row.FindControl("CheckSelect");
            Label LabVis = (Label)row.FindControl("LabNameVisible");
            if (Chk.Checked == true)
            {
                if (str == "")
                {
                    str = LabVis.Text.ToString();
                }
                else
                {
                    str = str + "," + LabVis.Text.ToString();
                }
            }
        }
        return str;
    }

    private string CheckCbxUpdate()
    {
        string str = string.Empty;
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];
            CheckBox Chk = (CheckBox)row.FindControl("CheckSelect");
            Label LabVis = (Label)row.FindControl("LabVisible");
            if (Chk.Checked == true)
            {
                if (str == "")
                {
                    str = LabVis.Text.ToString();
                }
                else
                {
                    str = str + "," + LabVis.Text.ToString();
                }
            }
        }
        return str;
    }


    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        string sql = "";

        if (ViewState["SortDirection"] == null || ViewState["SortDirection"].ToString().CompareTo("") == 0)
        {
            ViewState["SortDirection"] = " desc";
        }
        else
            ViewState["SortDirection"] = "";

        ViewState["OrderBY"] = " order by " + e.SortExpression + ViewState["SortDirection"];

        DataBindToGridview();
    }




    public override void VerifyRenderingInServerForm(Control control)
    { }

    protected void PagerButtonClick(object sender, EventArgs e)
    {
        try
        {
            GridView1.PageIndex = Convert.ToInt32(((LinkButton)sender).CommandName) - 1;
            DataBindToGridview();
        }
        catch
        {
            Response.Write("<script language='javascript'>alert('没有这么多页！');</script>");
            return;
        }
    }

    protected void Button1_Click1(object sender, EventArgs e)
    {
        try
        {
            if (GoPage.Text.Trim().ToString() == "")
            {
                Response.Write("<script language='javascript'>alert('页码不可以为空!');</script>");
            }
            else if (GoPage.Text.Trim().ToString() == "0" || Convert.ToInt32(GoPage.Text.Trim().ToString()) > GridView1.PageCount)
            {
                Response.Write("<script language='javascript'>alert('页码不是一个有效值!');</script>");
            }
            else if (GoPage.Text.Trim() != "")
            {
                int PageI = Int32.Parse(GoPage.Text.Trim()) - 1;
                if (PageI >= 0 && PageI < (GridView1.PageCount))
                {
                    GridView1.PageIndex = PageI;
                }
            }
            DataBindToGridview();
        }
        catch
        {
            DataBindToGridview();
            Response.Write("<script language='javascript'>alert('请输入有效的页码字符！');</script>");
        }
    }


    protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("ResponBm_qx.aspx?id=" + CheckCbxUpdate() + "");
    }

    public string ReturnValue(string departID)
    {
        return new DADepartMent().ReturnJgName(departID);
    }

 

 

}
